home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000…tember: Reference Library / Dev.CD Sep 00 RL Disk 1.toast / mac / Technical Documentation / Develop / Additional Articles / Developing Symbiotic Apps / Symbiotic Samples / UAppleEvents.cp Folder / StPPCBrowser.cp < prev    next >
Encoding:
Text File  |  1996-10-28  |  2.2 KB  |  86 lines  |  [TEXT/CWIE]

  1. // StPPCBrowser © 1995 Nick Beadman
  2. //    Implementation of class to prompt user for apple event target
  3.  
  4. #include <LString.h>
  5. #include <UException.h>
  6. #include "StPPCBrowser.h"
  7.  
  8. ConstSFTypeListPtr StPPCBrowser::sCreators;
  9. Int16 StPPCBrowser::sNofCreators;
  10. Boolean StPPCBrowser::sAllowLocal;
  11.  
  12. StPPCBrowser::StPPCBrowser(Int16 inNofCreators, ConstSFTypeListPtr inCreators, TargetID& ioTarget, Boolean inDefaultTarget, 
  13.                         Boolean inAllowLocal, ConstStr255Param inPrompt, ConstStr255Param inAppLabel)
  14. {
  15.     // store the statics needed to do port filtering
  16.     sCreators = inCreators;
  17.     sNofCreators = inNofCreators;
  18.     sAllowLocal = inAllowLocal;
  19.  
  20.     // assign the existing target ID to locals
  21.     LocationNameRec lLocation;
  22.     PortInfoRec lPortInfo;
  23.     lLocation = ioTarget.location;
  24.     lPortInfo.name = ioTarget.name;
  25.     
  26.     // make a port filter function;
  27.     PPCFilterUPP lPortFilter = NewPPCFilterProc(PortFilter);
  28.  
  29.     {
  30. #ifdef Debug_Throw
  31.         // It IS okay for the call to fail (user may cancel), so turn off Throw debugging.
  32.         StValueChanger<EDebugAction>okayToFail(gDebugThrow, debugAction_Nothing);
  33. #endif
  34.  
  35.         OSErr lErr = ::PPCBrowser(inPrompt, inAppLabel, inDefaultTarget, &lLocation, &lPortInfo, lPortFilter, 0);
  36.         
  37.         // dispose of the port filter UPP
  38.         DisposeRoutineDescriptor(lPortFilter);
  39.         
  40.         // assign the target to the location and port info
  41.         ioTarget.location = lLocation;
  42.         ioTarget.name = lPortInfo.name;
  43.         
  44.         ThrowIfOSErr_(lErr);
  45.     }
  46. }
  47.  
  48. StPPCBrowser::~StPPCBrowser()
  49. {
  50. }
  51.  
  52. pascal Boolean StPPCBrowser::PortFilter(LocationNamePtr inLocation, PortInfoPtr inPortInfo)
  53. {
  54.     Boolean lAllowInList = true;
  55.     
  56.     if (!(sAllowLocal) && (inLocation->locationKindSelector == ppcNoLocation))
  57.     {
  58.         lAllowInList = false;
  59.     }
  60.     else
  61.     {
  62.         // the first 4 chars of the port type string seems to be the creator !
  63.         //    this is undocumented %%%%
  64.         
  65.         // assume not in list if we have a list of creators
  66.         if (sNofCreators != 0)
  67.         {
  68.             lAllowInList = false;
  69.         }
  70.         
  71.         // get the port creator and compare with our creators
  72.         LStr255 lPortCreator = inPortInfo->name.u.portTypeStr;
  73.         for (Int16 i = 0; i < sNofCreators; i++)
  74.         {
  75.             LStr255 lCreator = sCreators[i];
  76.             if (lPortCreator.BeginsWith(lCreator))
  77.             {
  78.                 lAllowInList = true;
  79.                 break;
  80.             }
  81.         }
  82.     }
  83.     
  84.     return lAllowInList;
  85. }
  86.